import java.util.Scanner;

/**
 * 素数伴侣
 * 若两个正整数的和为素数，则这两个正整数称之为“素数伴侣”，如2和5、6和13，
 * Created by JiaJia on 2019/6/24 0024.
 */
public class HuaWei027 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            int n=scanner.nextInt();
            int[] arr=new int[n];
            for (int i = 0; i <n ; i++) {
                arr[i]=scanner.nextInt();
            }
            System.out.println(countPrimePairs(arr));
        }scanner.close();
    }
    public static boolean isPrime(int v){
        if (v<2){
            return false;
        }
        int sqrt=(int)Math.sqrt(v);
        for (int i = 2; i <=sqrt ; i++) {
            if (v%i==0){
                return false;
            }
        }

        return true;
    }

    private static int countPrimePairs(int[] arr){
        int[] dp=new int[arr.length+1];
        for (int i = arr.length-2; i >=0 ; i--) {
            for (int j = arr.length-1; j >i ; j--) {
                int cnt= isPrime(arr[i]+arr[j])?dp[i+1]+dp[j+1]+1-dp[j]:dp[i+1];
                dp[i]=(cnt>dp[i]?cnt:dp[i]);
            }
        }
        return dp[0];
    }
}